package lapsnake.model.stmt;

import lapsnake.model.*;
import lapsnake.model.data.*;
import lapsnake.py.ast.ASTHelperFactory; 
import lapsnake.ui.JTreeLabel;

import java.awt.Component;
import java.beans.PropertyVetoException;

import org.python.antlr.ast.*;

/**Wrapper class with helper functions for For nodes*/
public class LapFor extends LapStatement {
	//(expr target, expr iter, stmt* body, stmt* orelse
	public final SingleChild<LapExpression> target = new SingleChild<>(this, LapExpression.class);
	public final SingleChild<LapExpression> iter = new SingleChild<>(this, LapExpression.class);
	@NewRow public final ChildList<LapStatement> body = new ChildList<>(this, LapStatement.class, false);
	@NewRow public final ChildList<LapStatement> orelse = new ChildList<>(this, LapStatement.class, true);
	
	public LapFor(PyAST pyAST, ChildField<? super LapFor> parent, For node) throws PropertyVetoException {
		super(pyAST, parent, node);

		ASTHelperFactory.makeHelper(pyAST, target, node.getInternalTarget());
		ASTHelperFactory.makeHelper(pyAST, iter, node.getInternalIter());
		ASTHelperFactory.makeHelpers(pyAST, body, node.getInternalBody());
		ASTHelperFactory.makeHelpers(pyAST, orelse, node.getInternalOrelse());
		
		buildTextNodes(node);
	}
	
	@Override
	protected Component getFillerComponent(int childIndex,
		ChildField<?> childField)
	{
		if(childField == target)
    		return new JTreeLabel("For", false);
		else if(childField == iter)
    		return new JTreeLabel("in", false);
    	else if(childField == body)
    		return new JTreeLabel("Do:", true);
    	else
    		return new JTreeLabel("Else:", true);
	}
}
